package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 杨磊
 * @Description: 公海池规则枚举类
 * @date 2022/4/24 15:24
 */
@Getter
public enum CustomerSeniorRuleTypeEnum {
    /**
     * 转移规则
     */
    TRANSFER_RULE(1, "enum.customerSeniorRule.name.transfer_rule", "rule1"),
    /**
     * 退回规则
     */
    BACK_RULE(2, "enum.customerSeniorRule.name.back_rule", "rule2"),
    /**
     * 最大拥有客户数规则
     */
    MAX_CUSTOMER_NUM_RULE(3, "enum.customerSeniorRule.name.max_customer_num_rule", "rule4"),
    /**
     * 前负责人规则
     */
    PRE_PRINCIPAL_RULE(4, "enum.customerSeniorRule.name.pre_principal_rule", "rule5"),
    /**
     * 捞取频率限制规则
     */
    GAIN_RATE_RULE(5, "enum.customerSeniorRule.name.gain_rate_rule", "rule6"),
    /**
     * 未知规则,当异常时用于返回
     */
    UNKNOWN(404, "enum.customerSeniorRule.name.unknown", "unknown");


    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;

    /**
     * 枚举描述 --英文名称
     */
    private final String alias;


    /**
     * 构造一个<code>SubModuleEnum</code>枚举对象
     *
     * @param code  枚举值
     * @param name  枚举名
     * @param alias 别名
     */
    CustomerSeniorRuleTypeEnum(int code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 通过枚举<code>alias</code>获得枚举
     *
     * @param alias 别名
     * @return PublicCustomerRuleEnum
     */
    public static CustomerSeniorRuleTypeEnum getByAlias(String alias) {
        for (CustomerSeniorRuleTypeEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code 枚举值
     * @return PublicCustomerRuleEnum
     */
    public static CustomerSeniorRuleTypeEnum getByCode(Integer code) {
        for (CustomerSeniorRuleTypeEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<PublicCustomerRuleEnum>
     */
    public static List<CustomerSeniorRuleTypeEnum> getAllEnum() {
        List<CustomerSeniorRuleTypeEnum> list = new ArrayList<>();
        for (CustomerSeniorRuleTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (CustomerSeniorRuleTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

}
